package vista;

import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.table.AbstractTableModel;

import bean.JTextFieldValidator;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class VentanaOrden extends javax.swing.JFrame implements modelo.abstractfactory.AbstractFactoryVentana {

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	private JPanel panOrden;
	private JTextField txtFecha;
	private JLabel lblFecha;
	private JButton btnSalir;
	private JButton btnCancelar;
	private JButton btnGuardar;
	private JTextField txtTotal;
	private JLabel lblTotal;
	private JButton btnRemover;
	private JTable tblDetalleOrden;
	private JLabel lblDetalleOrden;
	private JScrollPane scpDetalleOrden;
	private JButton btnAceptar;
	private JTextFieldValidator txtCantidadProducto;
	private JLabel lblCantidadProducto;
	private JComboBox cmbProducto;
	private JComboBox cmbCategoria;
	private JLabel lblSeleccioneProducto;
	private JTextFieldValidator txtNombre;
	private JLabel lblSeleccioneCategoria;
	private JLabel lblProducto;
	private JTextField txtNoOrden;
	private JLabel lblNoOrden;
	private JButton btnBuscar;
	private JTextFieldValidator txtDireccion;
	private JTextFieldValidator txtCedula;
	private JLabel lblDireccion;
	private JLabel lblNombre;
	private JLabel lblCedula;
	
	private VentanaDetalleOrdenModeloTabla detalleOrden;
	
	private static VentanaOrden instancia;

	public final static synchronized VentanaOrden getInstancia() {
		if (instancia == null)
			instancia = new VentanaOrden();
		return instancia;
	}
		
	public VentanaOrden() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			setTitle("Registrar Orden");
			{
				panOrden = new JPanel();
				getContentPane().add(panOrden, BorderLayout.CENTER);
				panOrden.setLayout(null);
				panOrden.setPreferredSize(new java.awt.Dimension(759, 495));
				panOrden.setBackground(new java.awt.Color(255,255,255));
				{
					lblCedula = new JLabel();
					panOrden.add(lblCedula);
					lblCedula.setText("Cedula");
					lblCedula.setBounds(59, 41, 70, 14);
					lblCedula.setFont(new java.awt.Font("Comic Sans MS",1,12));
					lblCedula.setForeground(new java.awt.Color(18,6,249));
				}
				{
					lblNombre = new JLabel();
					panOrden.add(lblNombre);
					lblNombre.setText("Nombre");
					lblNombre.setBounds(59, 67, 70, 14);
					lblNombre.setFont(new java.awt.Font("Comic Sans MS",1,12));
					lblNombre.setForeground(new java.awt.Color(18,6,249));
				}
				{
					lblDireccion = new JLabel();
					panOrden.add(lblDireccion);
					lblDireccion.setText("Direccion");
					lblDireccion.setBounds(59, 93, 70, 14);
					lblDireccion.setFont(new java.awt.Font("Comic Sans MS",1,12));
					lblDireccion.setForeground(new java.awt.Color(18,6,249));
				}
				{
					txtCedula = new JTextFieldValidator(8, JTextFieldValidator.SOLO_NUMEROS);
					panOrden.add(txtCedula);
					txtCedula.setBounds(147, 35, 123, 25);
				}
				{
					txtNombre = new JTextFieldValidator(JTextFieldValidator.LETRAS_Y_ESPACIOS);
					panOrden.add(txtNombre);
					txtNombre.setMaximaLongitud(40);
					txtNombre.setBounds(147, 61, 123, 25);
				}
				{
					txtDireccion = new JTextFieldValidator(JTextFieldValidator.LETRAS_Y_ESPACIOS);
					panOrden.add(txtDireccion);
					txtDireccion.setMaximaLongitud(50);
					txtDireccion.setBounds(147, 87, 123, 25);
				}
				{
					btnBuscar = new JButton();
					panOrden.add(btnBuscar);
					btnBuscar.setText("Buscar");
					btnBuscar.setBounds(300, 31, 90, 28);
					btnBuscar.setForeground(new java.awt.Color(252,221,3));
					btnBuscar.setFont(new java.awt.Font("Comic Sans MS",1,12));
					btnBuscar.setBackground(new java.awt.Color(18,6,249));
					btnBuscar.setIcon(new ImageIcon(getClass().getClassLoader().getResource("iconos/buscar.gif")));
				}
				{
					lblNoOrden = new JLabel();
					panOrden.add(lblNoOrden);
					lblNoOrden.setText("No. Orden");
					lblNoOrden.setBounds(424, 41, 78, 14);
					lblNoOrden.setFont(new java.awt.Font("Comic Sans MS",1,12));
					lblNoOrden.setForeground(new java.awt.Color(18,6,249));
				}
				{
					txtNoOrden = new JTextField();
					panOrden.add(txtNoOrden);
					txtNoOrden.setBounds(514, 35, 83, 25);
					txtNoOrden.setEditable(false);
					txtNoOrden.setForeground(new java.awt.Color(255,0,0));
				}
				{
					lblProducto = new JLabel();
					panOrden.add(lblProducto);
					lblProducto.setText("PRODUCTOS");
					lblProducto.setBounds(162, 141, 85, 14);
				}
				{
					lblSeleccioneCategoria = new JLabel();
					panOrden.add(lblSeleccioneCategoria);
					lblSeleccioneCategoria.setText("Seleccione Categoria");
					lblSeleccioneCategoria.setBounds(47, 165, 124, 14);
					lblSeleccioneCategoria.setFont(new java.awt.Font("Comic Sans MS",1,12));
					lblSeleccioneCategoria.setForeground(new java.awt.Color(18,6,249));
				}
				{
					lblSeleccioneProducto = new JLabel();
					panOrden.add(lblSeleccioneProducto);
					lblSeleccioneProducto.setText("Seleccione Producto");
					lblSeleccioneProducto.setBounds(47, 196, 124, 14);
					lblSeleccioneProducto.setFont(new java.awt.Font("Comic Sans MS",1,12));
					lblSeleccioneProducto.setForeground(new java.awt.Color(18,6,249));
				}
				{
					ComboBoxModel cmbCategoriaModel = 
						new DefaultComboBoxModel();
					cmbCategoria = new JComboBox();
					panOrden.add(cmbCategoria);
					cmbCategoria.setModel(cmbCategoriaModel);
					cmbCategoria.setBounds(183, 161, 207, 21);
				}
				{
					ComboBoxModel cmbProductoModel = 
						new DefaultComboBoxModel();
					cmbProducto = new JComboBox();
					panOrden.add(cmbProducto);
					cmbProducto.setModel(cmbProductoModel);
					cmbProducto.setBounds(183, 192, 207, 21);
				}
				{
					lblCantidadProducto = new JLabel();
					panOrden.add(lblCantidadProducto);
					lblCantidadProducto.setText("Cantidad Producto");
					lblCantidadProducto.setBounds(47, 234, 124, 14);
					lblCantidadProducto.setFont(new java.awt.Font("Comic Sans MS",1,12));
					lblCantidadProducto.setForeground(new java.awt.Color(18,6,249));
				}
				{
					txtCantidadProducto = new JTextFieldValidator(3, JTextFieldValidator.SOLO_NUMEROS);
					panOrden.add(txtCantidadProducto);
					txtCantidadProducto.setBounds(183, 228, 58, 23);
				}
				{
					btnAceptar = new JButton();
					panOrden.add(btnAceptar);
					btnAceptar.setText("Aceptar");
					btnAceptar.setBounds(390, 226, 96, 28);
					btnAceptar.setForeground(new java.awt.Color(252,221,3));
					btnAceptar.setFont(new java.awt.Font("Comic Sans MS",1,12));
					btnAceptar.setBackground(new java.awt.Color(18,6,249));
					btnAceptar.setIcon(new ImageIcon(getClass().getClassLoader().getResource("iconos/icon_accept.gif")));
				}
				{
					scpDetalleOrden = new JScrollPane();
					panOrden.add(scpDetalleOrden);
					scpDetalleOrden.setBounds(47, 298, 571, 111);
					{
						tblDetalleOrden = new JTable();
						detalleOrden = new VentanaDetalleOrdenModeloTabla();
						scpDetalleOrden.setViewportView(tblDetalleOrden);
						tblDetalleOrden.setModel(detalleOrden);
					}
				}
				{
					lblDetalleOrden = new JLabel();
					panOrden.add(lblDetalleOrden);
					lblDetalleOrden.setText("DETALLE ORDEN");
					lblDetalleOrden.setBounds(270, 264, 154, 20);
					lblDetalleOrden.setForeground(new java.awt.Color(18,6,249));
					lblDetalleOrden.setFont(new java.awt.Font("Comic Sans MS",1,14));
				}
				{
					btnRemover = new JButton();
					panOrden.add(btnRemover);
					btnRemover.setText("Remover");
					btnRemover.setBounds(502, 226, 114, 28);
					btnRemover.setForeground(new java.awt.Color(252,221,3));
					btnRemover.setFont(new java.awt.Font("Comic Sans MS",1,12));
					btnRemover.setBackground(new java.awt.Color(18,6,249));
					btnRemover.setIcon(new ImageIcon(getClass().getClassLoader().getResource("iconos/eliminar.gif")));
				}
				{
					lblTotal = new JLabel();
					panOrden.add(lblTotal);
					lblTotal.setText("Total");
					lblTotal.setBounds(47, 444, 55, 14);
					lblTotal.setForeground(new java.awt.Color(18,6,249));
					lblTotal.setFont(new java.awt.Font("Comic Sans MS",1,12));
				}
				{
					txtTotal = new JTextField();
					panOrden.add(txtTotal);
					txtTotal.setBounds(114, 441, 83, 25);
					txtTotal.setEditable(false);
					txtTotal.setForeground(new java.awt.Color(255,0,0));
				}
				{
					btnGuardar = new JButton();
					panOrden.add(btnGuardar);
					btnGuardar.setText("Guardar");
					btnGuardar.setBounds(413, 431, 100, 41);
					btnGuardar.setForeground(new java.awt.Color(252,221,3));
					btnGuardar.setFont(new java.awt.Font("Comic Sans MS",1,12));
					btnGuardar.setBackground(new java.awt.Color(18,6,249));
					btnGuardar.setIcon(new ImageIcon(getClass().getClassLoader().getResource("iconos/disk.gif")));
				}
				{
					btnCancelar = new JButton();
					panOrden.add(btnCancelar);
					btnCancelar.setText("Cancelar");
					btnCancelar.setBounds(289, 431, 110, 41);
					btnCancelar.setForeground(new java.awt.Color(252,221,3));
					btnCancelar.setFont(new java.awt.Font("Comic Sans MS",1,12));
					btnCancelar.setBackground(new java.awt.Color(18,6,249));
					btnCancelar.setIcon(new ImageIcon(getClass().getClassLoader().getResource("iconos/cancelar.gif")));
				}
				{
					btnSalir = new JButton();
					panOrden.add(btnSalir);
					btnSalir.setText("Salir");
					btnSalir.setBounds(525, 431, 93, 41);
					btnSalir.setForeground(new java.awt.Color(252,221,3));
					btnSalir.setFont(new java.awt.Font("Comic Sans MS",1,12));
					btnSalir.setBackground(new java.awt.Color(18,6,249));
					btnSalir.setIcon(new ImageIcon(getClass().getClassLoader().getResource("iconos/cross.gif")));
				}
				{
					lblFecha = new JLabel();
					panOrden.add(lblFecha);
					lblFecha.setText("Fecha");
					lblFecha.setBounds(424, 67, 50, 14);
					lblFecha.setFont(new java.awt.Font("Comic Sans MS",1,12));
					lblFecha.setForeground(new java.awt.Color(18,6,249));
				}
				{
					txtFecha = new JTextField();
					panOrden.add(txtFecha);
					txtFecha.setBounds(514, 61, 83, 25);
					txtFecha.setEditable(false);
				}
			}
			pack();
			this.setSize(668, 530);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	public void addListener(ActionListener actionlistener){
		this.btnBuscar.addActionListener(actionlistener);
		this.cmbCategoria.addActionListener(actionlistener);
		this.btnAceptar.addActionListener(actionlistener);
		this.btnRemover.addActionListener(actionlistener);
		this.btnGuardar.addActionListener(actionlistener);
		this.btnCancelar.addActionListener(actionlistener);
		this.btnSalir.addActionListener(actionlistener);
	}
	
	public String getCedula(){
		return this.txtCedula.getText();
	}
	
	public String getNombre(){
		return this.txtNombre.getText();
	}
	
	public String getDireccion(){
		return this.txtDireccion.getText();
	}

	public void setNombre(String nombre){
		this.txtNombre.setText(nombre);
	}
	
	public void setDireccion(String direccion){
		this.txtDireccion.setText(direccion);
	}
	
	public void setNoOrden(String numero){
		this.txtNoOrden.setText(numero);
	}
	
	public String getNoOrden(){
		return this.txtNoOrden.getText();
	}
	
	public void cargarComboCategoria(Vector<String> vect)
	{
		ComboBoxModel cmbCategoriaModel = 
				new DefaultComboBoxModel(vect);
		cmbCategoria.setModel(cmbCategoriaModel);
	}
	
	public String getComboCategoria(){
		return cmbCategoria.getSelectedItem().toString();
	}
	
	public String getComboProducto(){
		return cmbProducto.getSelectedItem().toString();
	}
	
	public void cargarComboProducto(Vector<String> vect)
	{
		ComboBoxModel cmbProductoModel = 
			new DefaultComboBoxModel(vect);
		cmbProducto.setModel(cmbProductoModel);
	}
	
	public String getCantidadProducto(){
		return txtCantidadProducto.getText();
	}
	
	public VentanaDetalleOrdenModeloTabla getDetalleOrden(){
		return detalleOrden;
	}
	
	public void setDetalleOrden(AbstractTableModel abstractTableModel) {
		tblDetalleOrden.setModel(abstractTableModel);
	}
	
	public void borrarDatos(){
		txtCedula.setText("");
		txtNombre.setText("");
		txtDireccion.setText("");
		txtCantidadProducto.setText("");
		txtTotal.setText("");
		detalleOrden = new VentanaDetalleOrdenModeloTabla();
		tblDetalleOrden.setModel(detalleOrden);
	}
	
	public void mostrarMensaje(String mensaje) {
		JOptionPane.showMessageDialog(this, mensaje);
	}
	
	public void setTotal(String totalpagar){
		txtTotal.setText(totalpagar);
	}
	
	public String getTotal(){
		return txtTotal.getText();
	}
	
	public int seleccionDetalleOrden(){
		return tblDetalleOrden.getSelectedRow();
	}
	
	public void setFecha(String fecha){
		txtFecha.setText(fecha);
	}
	
	public String getFecha(){
		return txtFecha.getText();
	}
	
	public JComboBox getCategoria(){
		return this.cmbCategoria;
	}
	
}
